/**
 * [一句话描述该类的功能]
 *
 * @author : [kai]
 * @version : [v1.0]
 * @createTime : [2022/10/30 22:38]
 */


package com.find.controller;

import com.find.controller.utils.R;
import com.find.domain.User;
import com.find.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Api(tags="退出登录")
@RestController
@RequestMapping("/logout")
public class LogoutController {
    @Autowired
    private UserService userService;
    @PostMapping
    @ApiImplicitParam(name="user",dataType="User",required=true,value="用户类，只需传入name值")
    @ApiOperation("退出登录")
    public R logout(@RequestBody User user
            ,HttpServletResponse response)throws IOException{
        if(user.getName()==null){
            response.setStatus(500);
            return new R(false,"没有传入用户名");
        }
        boolean flag=userService.logout(user.getName());
        response.setStatus(flag?200:500);
        return new R(flag,flag?"退出登录":"退出失败");
    }
}
